'use strict';

goog.provide('Blockly.Blocks.sensors');
goog.require('Blockly.Blocks');

Blockly.Msg['STORERS_HUE'] = 40;

Blockly.Blocks.xnr_encoder_setup= {
    init: function() { 
    this.appendValueInput("xin_nong_r_x1")
        .setCheck(null)
        .setAlign(Blockly.ALIGN_CENTRE)
        .appendField("初始设置")
        .appendField(new Blockly.FieldDropdown([["编码器1","1"],["编码器2","2"],["编码器3","3"],["编码器4","4"]]), "xin_nong_r_x3")
        .appendField("    管脚#IN1");
    this.appendValueInput("xin_nong_r_x2")
        .setCheck(null)
        .appendField("管脚#IN2");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(Blockly.Msg['STORERS_HUE']);
    this.setTooltip();
    this.setHelpUrl("https://github.com/mathertel/RotaryEncoder");
    }
};

Blockly.Blocks.xnr_encoder_poll= {
    init: function() { 
    this.appendDummyInput()
        .appendField(new Blockly.FieldDropdown([["编码器1","1"],["编码器2","2"],["编码器3","3"],["编码器4","4"]]), "xin_nong_r_x8")
        .appendField("执行轮询");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(Blockly.Msg['STORERS_HUE']);
    this.setTooltip("每隔几毫秒调用这个函数，或者使用一个中断来处理旋转编码器的状态变化");
    this.setHelpUrl("");
    }
};

Blockly.Blocks.xnr_encoder_get= {
    init: function() { 
    this.appendDummyInput()
        .appendField("读取")
        .appendField(new Blockly.FieldDropdown([["编码器1","1"],["编码器2","2"],["编码器3","3"],["编码器4","5"]]), "xin_nong_r_x6")
        .appendField(new Blockly.FieldDropdown([["位置","getPosition"],["方向","getDirection"],["时间间隔","getMillisBetweenRotations"]]), "xin_nong_r_x4");
    this.setInputsInline(true);
    this.setOutput(true, null);
    this.setColour(Blockly.Msg['STORERS_HUE']);
    this.setTooltip("getPosition() 获取当前位置值；getDirection()  返回编码器当前旋转方向 ，简单检索旋钮上次旋转的方向，0 =不旋转，1 =顺时针，-1 =逆时针；getMillisBetweenRotations() 返回当前观察到的时间间隔(以毫秒为单位)");
    this.setHelpUrl("");
    }
};

Blockly.Blocks.xnr_encoder_setPosition= {
    init: function() { 
    this.appendValueInput("xin_nong_r_x5")
        .setCheck(null)
        .appendField("设置")
        .appendField(new Blockly.FieldDropdown([["编码器1","1"],["编码器2","2"],["编码器3","3"],["编码器4","4"]]), "xin_nong_r_x7")
        .appendField("位置");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(Blockly.Msg['STORERS_HUE']);
    this.setTooltip("");
    this.setHelpUrl("");
    }
};

